// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import router from './router'
import 'element-ui/lib/theme-default/index.css'
import store from './store/index'
import ajax from './xiaobaoajax'

Vue.config.productionTip = false
const baseIp = 'http://www.51hyjj.com/admin/'
let $http = function (method, url, data) { // 异步请求的进一步封（偷）装（懒）
  return ajax({
    method: method,
    url: baseIp + url,
    data: data,
    async: true
  })
}
Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.prototype.$http = $http
Vue.prototype.imgUrl = baseIp
Vue.prototype.recomUrl = 'http://www.51hyjj.com/'
Date.prototype.format = function (time) { // 时间类型数据格式化方法
    let o = {
        'M+': this.getMonth() + 1,
        'd+': this.getDate(),
        'h+': this.getHours(),
        'm+': this.getMinutes(),
        's+': this.getSeconds()
    }
    if (/(y+)/.test(time)) time = time.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
    for (var k in o) {
        if (new RegExp('(' + k + ')').test(time)) time = time.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
    }
    return time
}
// Object.prototype.toeach = function (callback) {
//   var that = this
//   Object.keys(this).forEach(function (item) {
//     callback(item, that[item]).bind({item: that[item]})
//   })
// }
// this.$http('get', 'music', data) // data 可以为空
// .then((data) => {
//   // TODO:
//   return this.$http('post', 'article', data) // 如果要进行二次请求，则先返回promise对象
// })
// .then((data) => { // 链式调用 此data为第二次请求返回的数据
//
// })

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
